package cn.bluemobi.app.controller.member;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.app.core.controller.AppBaseController;
import cn.bluemobi.app.entity.output.BankCard;
import cn.bluemobi.app.entity.output.Member;
import cn.bluemobi.app.entity.output.Team;
import cn.bluemobi.app.entity.output.Withdrawals;
import cn.bluemobi.app.service.MemberService;
import cn.bluemobi.common.core.dto.Dto;
import cn.bluemobi.common.core.dto.ListDto;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Controller
@RequestMapping("/member")
@Api(description = "用户相关", value = "member")
public class MemberController extends AppBaseController {

	@Autowired
	private MemberService memberService;

	@ApiOperation(value = "注册", httpMethod = "POST")
	@RequestMapping("/register")
	@ResponseBody
	public Dto<Member> register(
			@ApiParam("手机号") @RequestParam(value = "cellphone") String cellphone,
			@ApiParam("密码") @RequestParam(value = "password") String password,
			@ApiParam("验证码") @RequestParam(value = "verifyCode") String verifyCode,
			@ApiParam("邀请码") @RequestParam(value = "inviteCode", required = false) String inviteCode) {
		return memberService.register(cellphone, password, verifyCode,
				inviteCode);
	}

	@ApiOperation(value = "登录", httpMethod = "POST")
	@RequestMapping("/login")
	@ResponseBody
	public Dto<Member> login(
			@ApiParam("手机号") @RequestParam(value = "cellphone") String cellphone,
			@ApiParam("密码") @RequestParam(value = "password") String password) {
		return memberService.login(cellphone, password);
	}

	@ApiOperation(value = "忘记密码", httpMethod = "POST")
	@RequestMapping("/forgetPassword")
	@ResponseBody
	public Dto<Object> forgetPassword(
			@ApiParam("手机号") @RequestParam("cellphone") String cellphone,
			@ApiParam("新密码") @RequestParam("password") String password,
			@ApiParam("验证码") @RequestParam("verifyCode") String verifyCode) {
		return memberService.forgetPassword(cellphone, password, verifyCode);
	}

	@ApiOperation(value = "查询个人信息", httpMethod = "POST")
	@RequestMapping("/findPersonDetail")
	@ResponseBody
	public Dto<Member> findPersonDetail(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId) {
		return memberService.findPersonDetail(memberId);
	}

	@ApiOperation(value = "更新个人信息", httpMethod = "POST")
	@RequestMapping("/updatePersonDetail")
	@ResponseBody
	public Dto<Member> updatePersonDetail(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("头像") @RequestParam(value = "headImg", required = false) String headImg,
			@ApiParam("昵称") @RequestParam(value = "nickName", required = false) String nickName,
			@ApiParam("性别（0保密，1男，2女）") @RequestParam(value = "sex", required = false) String sex) {
		return memberService.updatePersonDetail(memberId, headImg, nickName,
				sex);
	}

	@ApiOperation(value = "查询银行卡信息", httpMethod = "POST")
	@RequestMapping("/findBankCardList")
	@ResponseBody
	public ListDto<BankCard> findBankCardList(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId) {
		return memberService.findBankCardList(memberId);
	}

	@ApiOperation(value = "添加银行卡", httpMethod = "POST")
	@RequestMapping("/addBankCard")
	@ResponseBody
	public Dto<Object> addBankCard(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("银行卡号") @RequestParam("bankCardNumber") String bankCardNumber,
			@ApiParam("银行卡预留姓名") @RequestParam("reservedName") String reservedName,
			@ApiParam("银行名") @RequestParam("bankName") String bankName,
			@ApiParam("支行") @RequestParam("bankBranch") String bankBranch) {
		return memberService.addBankCard(memberId, bankCardNumber,
				reservedName, bankName, bankBranch);
	}

	@ApiOperation(value = "删除银行卡", httpMethod = "POST")
	@RequestMapping("/deleteBankCard")
	@ResponseBody
	public Dto<Object> deleteBankCard(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("银行卡id") @RequestParam("bankCardId") String bankCardId) {
		return memberService.deleteBankCard(memberId, bankCardId);
	}

	@ApiOperation(value = "申请提现", httpMethod = "POST")
	@RequestMapping("/applyWithdrawals")
	@ResponseBody
	public Dto<Object> applyWithdrawals(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("银行卡id") @RequestParam("bankCardId") String bankCardId,
			@ApiParam("提现金额") @RequestParam("money") String money,
			@ApiParam("手续费") @RequestParam("brokerage") String brokerage,
			@ApiParam("实付金额") @RequestParam("payMoney") String payMoney) {
		return memberService.applyWithdrawals(memberId, bankCardId, money,
				brokerage, payMoney);
	}

	@ApiOperation(value = "提现记录", httpMethod = "POST")
	@RequestMapping("/findWithdrawalsList")
	@ResponseBody
	public ListDto<Withdrawals> findWithdrawalsList(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId) {
		return memberService.findWithdrawalsList(memberId);
	}

	@ApiOperation(value = "申请认证", httpMethod = "POST")
	@RequestMapping("/applyIdentification")
	@ResponseBody
	public Dto<Object> applyIdentification(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("姓名") @RequestParam("name") String name,
			@ApiParam("身份证号") @RequestParam("idCardNumber") String idCardNumber,
			@ApiParam("身份证照") @RequestParam("idCardImg") String idCardImg) {
		return memberService.applyIdentification(memberId, name, idCardNumber,
				idCardImg);
	}

	@ApiOperation(value = "查询会员下属团队", httpMethod = "POST")
	@RequestMapping("/findTeamList")
	@ResponseBody
	public ListDto<Team> findTeamList(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("邀请码") @RequestParam("inviteCode") String inviteCode) {
		return memberService.findTeamList(memberId, inviteCode);
	}

}
